﻿namespace OpenGameEngine.Input
{
    using System;
    using System.Reflection;
    using System.Windows.Forms;

    /// <summary>
    /// Tracks the state of the mouse and each button on it.
    /// </summary>
    public class MouseStateInfo : Object
    {
        private Boolean None;
        private Boolean Left;
        private Boolean Right;
        private Boolean Middle;
        private Boolean XButton1;
        private Boolean XButton2;

        /// <summary>
        /// Returns the mouse position
        /// </summary>
        public Vector2 MouseLocation { get; internal set; }

        /// <summary>
        /// Get the state for the mouse
        /// </summary>
        /// <param name="button"></param>
        /// <returns></returns>
        public Boolean this[MouseButtons button]
        {
            get
            {
                return GetButton(button);
            }
            set 
            {
                SetButton(button, value);
            }
        }

        private Boolean GetButton(MouseButtons button)
        {
            switch (button)
            {
                case MouseButtons.Left:
                    return Left;
                case MouseButtons.Middle:
                    return Middle;
                case MouseButtons.None:
                    return None;
                case MouseButtons.Right:
                    return Right;
                case MouseButtons.XButton1:
                    return XButton1;
                case MouseButtons.XButton2:
                    return XButton2;
            }
            return false;
        }

        /// <summary>
        /// Set the mousebutton's state.
        /// </summary>
        /// <param name="button"></param>
        /// <param name="val"></param>
        private void SetButton(MouseButtons button, Boolean val)
        {
            switch (button)
            {
                case MouseButtons.Left:
                    Left = val;
                    break;
                case MouseButtons.Middle:
                    Middle = val;
                    break;
                case MouseButtons.None:
                    None = val;
                    break;
                case MouseButtons.Right:
                    Right = val;
                    break;
                case MouseButtons.XButton1:
                    XButton1 = val;
                    break;
                case MouseButtons.XButton2:
                    XButton2 = val;
                    break;
            }
        }

        /// <summary>
        /// Set the mouse location
        /// </summary>
        /// <param name="val"></param>
        internal void SetLocation(Vector2 val)
        {
            MouseLocation = val;
        }

        public MouseStateInfo Clone()
        {
            return (MouseStateInfo)this.MemberwiseClone();
        }
    }
}
